package com.nuoniu.sibanyun.mapper.erp.in;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.bo.UsedGradeRuleBo;
import com.nuoniu.sibanyun.entity.erp.in.InWarehouse;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 仓库管理 Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-09-22
 */
public interface InWarehouseMapper extends BaseMapper<InWarehouse> {

    @Select("select * from scb_warehouse where company_id=#{companyId} and wh_code=#{whCode}")
    InWarehouse getByCode(InWarehouse inWarehouse);

    @Select("select * from scb_warehouse where company_id=#{companyId} and wh_name=#{whName}")
    InWarehouse getByName(InWarehouse inWarehouse);

    @Select("SELECT id FROM scb_warehouse WHERE  FIND_IN_SET( #{userId},wh_keeper) AND company_id = #{companyId} AND account_id = #{accountId} ")
    List<Long> listPersonalInWarehouseIds(Integer userId, Integer accountId, Integer companyId);

    @Select("SELECT id FROM scb_warehouse WHERE wh_department_id = #{officeId}  AND company_id = #{companyId} AND account_id = #{accountId} ")
    List<Long> listOfficeInWarehouseIds(Integer officeId, Integer accountId, Integer companyId);

    @Select("SELECT id FROM scb_warehouse WHERE company_id = #{companyId} AND account_id = #{accountId} ")
    List<Long> listCompanyInWarehouseIds(Integer accountId, Integer companyId);

    @Select("SELECT id FROM scb_warehouse WHERE ( FIND_IN_SET( #{userId},wh_keeper) OR wh_department_id in (${otherOfficeIds}) )AND company_id = #{companyId} AND account_id = #{accountId} ")
    List<Long> listOtherOfficesInWarehouseIds(String otherOfficeIds,Integer userId, Integer accountId, Integer companyId);

    @Select("SELECT id FROM scb_warehouse WHERE ( wh_keeper in ( ${otherUserIds})  OR FIND_IN_SET( #{userId},wh_keeper))AND company_id = #{companyId} AND account_id = #{accountId} ")
    List<Long> listOtherUsersInWarehouseIds(String otherUserIds,Integer userId,Integer accountId, Integer companyId);

    @Select("SELECT id FROM scb_warehouse WHERE ( FIND_IN_SET( #{userId},wh_keeper) OR wh_department_id in (${otherOfficeIds}) OR  wh_keeper in ( ${otherUserIds}))AND company_id = #{companyId} AND account_id = #{accountId} ")
    List<Long> listOtherOfficesAndOtherUsersInWarehouseIds(String otherOfficeIds,String otherUserIds,Integer userId, Integer accountId, Integer companyId);



//    @Select("SELECT * FROM scb_warehouse WHERE  FIND_IN_SET( #{userId},wh_keeper) AND company_id = #{companyId} AND account_id = #{accountId} ADN  ( wh_name LIKE CONCAT( '%', #{keyWord}, '%' ) OR wh_code  LIKE CONCAT( '%', #{keyWord}, '%' ) )")
    List<InWarehouse> listPersonalInWarehouses(Integer userId, Integer accountId, Integer companyId,String keyWord);

//    @Select("SELECT * FROM scb_warehouse WHERE company_id = #{companyId} AND account_id = #{accountId} AND  ( wh_name LIKE CONCAT( '%', #{keyWord}, '%' ) OR wh_code  LIKE CONCAT( '%', #{keyWord}, '%' ) )")
    List<InWarehouse> listCompanyInWarehouses(Integer accountId, Integer companyId,String keyWord);


    @Select("select storage_bin from scb_warehouse where id = #{inWarehouseId}")
    boolean isHaveInInventoryLocation(Long inWarehouseId);

}
